package basic.a1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Jdbc {
public static void main(String[] args) {
	try {
		Class.forName("oracle.jdbc.driver.OracleDriver");
		System.out.println("加载成功");
		Connection con=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:xe","hr","123");
		System.out.println("数据库连接成功");
		Statement stm=con.createStatement();  
		String sql="select a.first_name 姓名,a.salary 工资,a.department_id 部门号  from employees a where a.salary>"
				+"(select avg(e.salary)from employees e where a.department_id=e.department_id)"
				+"order by a.department_id";
		ResultSet rs=stm.executeQuery(sql);
		while(rs.next()){
			System.out.println(rs.getString(2));
		}
		rs.close();
		stm.close();
		con.close();
	} catch (ClassNotFoundException e) { 
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
}
